<?php
/*
 * @project CreativeFramework
 * @version <#RELEASE_VERSION#>
 * @license GNU Lesser General Public License
 * @author Jimmie Lin
 */

////////////////////////////////////////////////////
// Independent Script to load JS files.
// Does *not* minify, just uses some quick hacks to
// remove comments and then linebreaks.

define("PUBLIC_PATH", dirname(__FILE__).DIRECTORY_SEPARATOR);
define("JS_PATH", PUBLIC_PATH."js".DIRECTORY_SEPARATOR);
$contents = "";

// Compress function
// string compress(string Contents)
function compress($Contents) {
	// Remove All Comments
	$Contents = preg_replace("#/\*([\w|\d|,|\s|\*|@|(|)|/|\\\\|\-|\.|!|:|\?]*)\*/#si", "", $Contents); // /* format */
	$Contents = preg_replace("#//([\w|\d|,|\s|\*|@|(|)|/|\\\\|\-|\.|!|:|\?]*)#si", "", $Contents); // //Format
	
	// All linebreaks
	$Contents = str_replace("\n", "", $Contents);
	return $Contents;
}


if(isset($_GET['options'])) {
	
	
}
else { // Load ALL	
	$res = opendir(JS_PATH);
	while (($file = readdir ($res)) !== false) {
		if (!(($file == ".") || ($file == ".."))) {
			// Let's make sure it's a JS File
			$f = explode(".", $file);
			if($f[1] == "js") {
				$contents .= compress(file_get_contents(JS_PATH.$f[0].".".$f[1]))."\r\n";
				//echo "File $file passed check, length of contents is now ".strlen($contents)."<br>";
			}
		}
	}
	//echo "<xmp>".($contents)."</xmp>";
	$contents = "/**************************************
	Creative Framework Javascript File
	Generated ************************/".$contents;
	die($contents);
}
